package com.roc.steelend.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.roc.steelend.controller.vo.returnformat.ReturnMsgForTable;
import com.roc.steelend.mapper.BigAccountMapper;
import com.roc.steelend.pojo.BigAccount;
import com.roc.steelend.service.BigAccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional(rollbackFor =  Exception.class)
public class BigAccountServiceImpl implements BigAccountService {

    @Autowired
    private BigAccountMapper bigAccountMapper;
    @Override
    public ReturnMsgForTable findBigAccoutData(Integer now, Integer size, Integer isPayTakeId) {
        Page<BigAccount> page = new Page<>(now, size);
        QueryWrapper<BigAccount> wrapper = new QueryWrapper<>();
        if (isPayTakeId!=null && isPayTakeId!=0){
             wrapper.eq("is_pay_or_take",isPayTakeId);
        }
        ReturnMsgForTable returnMsgForTable = new ReturnMsgForTable();
        bigAccountMapper.selectPage(page,wrapper);
        returnMsgForTable.setObjectList(page.getRecords());
        returnMsgForTable.setCurrenPage(now);
        returnMsgForTable.setTotal(Integer.valueOf(String.valueOf(page.getTotal())));
        return returnMsgForTable;
    }

    @Override
    public List<BigAccount> findBigAccoutData2(Integer isPayTakeId) {

        QueryWrapper<BigAccount> wrapper = new QueryWrapper<>();
        if (isPayTakeId!=null && isPayTakeId!=0){
            wrapper.eq("is_pay_or_take",isPayTakeId);
        }

        return bigAccountMapper.selectList(wrapper);

    }
}
